<%@ page contentType="text/html; charset=utf-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="thx" uri="/thx-tags"%>
<style>
	.table .form-group{
		padding-left:0px;
		padding-right:0px;
	}
</style>
	<div class="box-header with-border">
		<div class="row"></div>
	</div>
	<div class="box-body no-padding">
		<form id="appConfig-base-form" name="ui-adminlte-form"
			data-toggle="validator" role="form" method="post" 
			action="${pageContext.request.contextPath}/workflow/appConfig!save.action"
			forward-action="${pageContext.request.contextPath}/workflow/appConfig!list.action">
			<s:token></s:token>
			<input name="id" value="${entity.appId }" type="hidden" />
			<table class="table">
				<tbody>
					<tr>
						<th>应用名称</th>
						<td>
							<div class="form-group col-sm-8">
								<input type="text" name="entity.appName" value="${entity.appName}" 
								remote="${pageContext.request.contextPath}/workflow/appConfig!checkAppName.action?id=${entity.appId }"
								class="form-control required" placeholder="应用名称"/>
							</div>
						</td>
					</tr>
					<tr>
						<th>应用描述</th>
						<td>
							<div class="form-group col-sm-8">
								<input type="text" 	name="entity.appDescribe" value="${entity.appDescribe}" class="form-control required" placeholder="应用描述"/>
							</div>
						</td>
					</tr>
					<tr>
						<th>应用属性</th>
						<td>
		                    <div class="radio-group">
		                        <label for="attr[0]">表单</label>
		                        <input type="radio" name="entity.appAttr" value="0"  <c:if test="${entity.appAttr=='0'}">checked</c:if> id="attr[0]" />
		                    </div>
		                    <div class="radio-group">
		                        <label for="attr[1]">公文</label>
		                        <input  type="radio" name="entity.appAttr" value="1" <c:if test="${entity.appAttr=='1'}">checked</c:if> id="attr[1]"/>
		                    </div>
		                    <div class="radio-group">
		                        <label for="attr[2]">外置表单</label>
		                        <input  type="radio" name="entity.appAttr" value="2" <c:if test="${entity.appAttr=='2'}">checked</c:if>  id="attr[2]"/>
		                    </div>
		                    <div class="radio-group">
		                        <label for="attr[5]">外置公文</label>
		                        <input  type="radio" name="entity.appAttr" value="3" <c:if test="${entity.appAttr=='3'}">checked</c:if> id="attr[5]"/>
		                    </div>
						</td>
					</tr>
<!-- 
					<tr>
						<th>应用表单</th>
						<td>
							<div class="form-group col-sm-6">
								 <select name="entity.appForm.appFormId" class="form-control">
								 <c:forEach items="${appFormList}" var="appForm">
					                <option  value="${appForm.appFormId}" <c:if test="${entity.appForm.appFormId==appForm.appFormId}">selected</c:if> >${appForm.description}</option>
								 </c:forEach>
			                     </select>
							</div>
						</td>
					</tr>
 -->					
					<tr>
						<th>应用处理</th>
						<td>
							<div class="form-group col-sm-6">
								 <select name="entity.handle.handleId" class="form-control">
					             <c:forEach items="${appHandleList}" var="appHandle">
					                <option  value="${appHandle.handleId}" <c:if test="${entity.handle.handleId==appHandle.handleId}">selected</c:if> >${appHandle.description}</option>
								 </c:forEach>
			                     </select>
							</div>
						</td>
					</tr>
					<tr>
						<th>应用类型</th>
						<td>
							<div class="form-group col-sm-6">
								 <select name="entity.appType.typeId" class="form-control" value="${entity.appType.typeId}">
					                <c:forEach items="${appTypeList}" var="appType">
					                	<option value="${appType.typeId}">${appType.typeName}</option>
					                </c:forEach>
			                     </select>
							</div>
						</td>
					</tr>
					<tr>
						<th>应用流程</th>
						<td>
							<div class="form-group col-sm-3" style="margin-right:10px">
								 <select name="entity.selectFlowId" class="form-control">
								    <option value=''>无流程</option>
					               <c:forEach items="${flowList}" var="flow">
					               		<option value="${flow.flowId}"  <c:if test="${entity.selectFlowId==flow.flowId}">selected</c:if>>${flow.flowName}</option>
					               </c:forEach>
			                     </select>
							</div>
							<div class="form-group col-sm-2" >
			                      <select name="entity.flowId" class="form-control" value="${entity.flowId}">
			                     </select>
							</div>
						</td>
					</tr>
					<tr>
						<th>公文模板</th>
						<td>
							<div class="form-group col-sm-6">
								<select name="entity.docTempath" class="form-control">
					            	<c:forEach items="${tempList}" var="arcTemplate">
					                	<option  value="${arcTemplate.recordId}"  <c:if test="${entity.docTempath==arcTemplate.recordId}">selected</c:if> >${arcTemplate.descript}</option>
								 	</c:forEach>
			                     </select>
							</div>
						</td>
					</tr>					
					<tr>
					<th>使用人员</th>
						<td>
							<div class="form-group col-sm-5" style="margin-right:10px">
								<input type = "text" class="form-control" name="perAuthority.authorityDataName" value="${perAuthority.authorityDataName }"/>  
								<input type = "hidden" name="perAuthority.authorityData" value="${perAuthority.authorityData }"/>  
								<input type = "hidden" name="perAuthority.authorityType" value="per"/>  
							</div>
							<button type="button" class="btn btn-primary" id = "select-user">选择</button>
							<button type="button" class="btn search-btn" onclick="cleanValue(this)">清除</button>
						</td>
					</tr>
					<tr>
					<th>使用部门</th>
						<td>
							<div class="form-group col-sm-5" style="margin-right:10px">
								<input type = "text" class="form-control" name="deptAuthority.authorityDataName" value="${deptAuthority.authorityDataName }"/>  
								<input type = "hidden" name="deptAuthority.authorityData" value="${deptAuthority.authorityData }"/>  
								<input type = "hidden" name="deptAuthority.authorityType" value="dept"/> 
							</div>
							<button type="button" class="btn btn-primary" id = "select-dept">选择</button>
							<button type="button" class="btn search-btn" onclick="cleanValue(this)">清除</button>
						</td>
					</tr>
					<tr>
					<th>使用角色</th>
						<td>
							<div class="form-group col-sm-5" style="margin-right:10px">
								<input type = "text" class="form-control" name="roleAuthority.authorityDataName" value="${roleAuthority.authorityDataName }"/>  
								<input type = "hidden" name="roleAuthority.authorityData" value="${roleAuthority.authorityData }"/>  
								<input type = "hidden" name="roleAuthority.authorityType" value="role"/> 
							</div> 
							<button type="button" class="btn btn-primary" id = "select-role">选择</button>
							<button type="button" class="btn search-btn" onclick="cleanValue(this)">清除</button>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="modal-footer">
				<button type="submit" class="btn btn-primary">提交</button>
			</div>
		</form>
	</div>
<script src="${pageContext.request.contextPath}/scripts/data-selector.js" ></script>
<script src="${pageContext.request.contextPath}/workflow/js/app-form.js" ></script>
<script src="${pageContext.request.contextPath}/workflow/js/base-info.js" ></script>
<script>
 $(function(){
	var onChecked = function(event){
		 var targetVal;
		  if(event){
			  targetVal = event.target.value;
		  }else{
			  targetVal = $('#appConfig-base-form input[name="entity.appAttr"]:checked').val();
		  }
		  //公文模板
		  if(targetVal=='1'||targetVal=='3'||targetVal=='5'){
			  $("#appConfig-base-form select[name='entity.docTempath']").removeAttr("disabled");
			  $("#appConfig-base-form select[name='entity.docTempath']").parents("tr").show();
		  }else{
			  $("#appConfig-base-form select[name='entity.docTempath']").attr("disabled","disabled");
			  $("#appConfig-base-form select[name='entity.docTempath']").parents("tr").hide();
		  }
		  //应用表单
		  if(targetVal=='2'||targetVal=='3'||targetVal=='4'||targetVal=='5'){
			  $("#appConfig-base-form select[name='entity.appForm.appFormId']").removeAttr("disabled");
			  $("#appConfig-base-form select[name='entity.appForm.appFormId']").parents("tr").show();
		  }else{
			  $("#appConfig-base-form select[name='entity.appForm.appFormId']").attr("disabled","disabled");
			  $("#appConfig-base-form select[name='entity.appForm.appFormId']").parents("tr").hide();
		  }
	 }
	 
	 icheckPlugin.init($('#appConfig-base-form input[name="entity.appAttr"]'),{ifChecked:onChecked}); 
	 
	 $("#appConfig-base-form select[name='entity.selectFlowId']").change();
	 
	 $("#appConfig-base-form select[name='entity.appType.typeId']").find("option[value='"+$("#appConfig-base-form select[name='entity.appType.typeId']").attr("value")+"']").attr("selected","selected");
	 
	 appform.init();
	 //执行初始控制事件
	 onChecked();
	 
 })
 function cleanValue(e){
	 //清除选项值 前两项
	 $(e).prevAll("div").find("input:lt(2)").val("");
 }
</script>
